<template>
    <view>
        <!--标题和返回-->
		<cu-custom :bgColor="NavBarColor" isBack :backRouterName="backRouteName">
			<block slot="backText">返回</block>
			<block slot="content">点位管理</block>
		</cu-custom>
		 <!--表单区域-->
		<view>
			<form>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">guid：</text></view>
                  <input  placeholder="请输入guid" v-model="model.guid"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">tag：</text></view>
                  <input  placeholder="请输入tag" v-model="model.tag"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">path：</text></view>
                  <input  placeholder="请输入path" v-model="model.path"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">name：</text></view>
                  <input  placeholder="请输入name" v-model="model.name"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">（1 空间节点   2设备节点   3 点位节点）：</text></view>
                  <input type="number" placeholder="请输入（1 空间节点   2设备节点   3 点位节点）" v-model="model.nodeType"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">删除状态：</text></view>
                  <input type="number" placeholder="请输入删除状态" v-model="model.delFlag"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">点位分类Point type：1=AI；2=DI；3=AO；
4=DO；5=Alarm。：</text></view>
                  <input  placeholder="请输入点位分类Point type：1=AI；2=DI；3=AO；
4=DO；5=Alarm。" v-model="model.pointType"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">点位的单位：</text></view>
                  <input  placeholder="请输入点位的单位" v-model="model.unit"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">DI/DO的取值含义。格式如：“1=开门;0=关
门”。 
DI/DO的取值含义。格式如：“1=开门;0=关 必须是数值型的值。：</text></view>
                  <input  placeholder="请输入DI/DO的取值含义。格式如：“1=开门;0=关
门”。 
DI/DO的取值含义。格式如：“1=开门;0=关 必须是数值型的值。" v-model="model.statusMap"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">告警级别：</text></view>
                  <input type="number" placeholder="请输入告警级别" v-model="model.alarmLevel"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">告警类型：</text></view>
                  <input type="number" placeholder="请输入告警类型" v-model="model.alarmType"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">上传数据的时间间隔，单位秒：</text></view>
                  <input type="number" placeholder="请输入上传数据的时间间隔，单位秒" v-model="model.period"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">变比：</text></view>
                  <input  placeholder="请输入变比" v-model="model.percentage"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">绝对值变比：</text></view>
                  <input  placeholder="请输入绝对值变比" v-model="model.absValue"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">AO的合法控制范围。max=30。默认NULL，
AO的合法控制范围。不生效。：</text></view>
                  <input  placeholder="请输入AO的合法控制范围。max=30。默认NULL，
AO的合法控制范围。不生效。" v-model="model.aoMaxBound"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">
围 ：</text></view>
                  <input  placeholder="请输入
围 " v-model="model.aoMinBound"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">parentGuid：</text></view>
                  <input  placeholder="请输入parentGuid" v-model="model.parentGuid"/>
                </view>
              </view>
				<view class="padding">
					<button class="cu-btn block bg-blue margin-tb-sm lg" @click="onSubmit">
						<text v-if="loading" class="cuIcon-loading2 cuIconfont-spin"></text>提交
					</button>
				</view>
			</form>
		</view>
    </view>
</template>

<script>
    import myDate from '@/components/my-componets/my-date.vue'

    export default {
        name: "FocPointForm",
        components:{myDate},
        props:{
          formData:{
              type:Object,
              default:() => ({}),
              required:false
          }
        },
        data(){
            return {
				CustomBar: this.CustomBar,
				NavBarColor: this.NavBarColor,
				loading:false,
                model: {},
                backRouteName:'index',
                url: {
                  queryById: "/foc/focPoint/queryById",
                  add: "/foc/focPoint/add",
                  edit: "/foc/focPoint/edit",
                },
            }
        },
        created(){
             this.initFormData();
        },
        methods:{
           initFormData(){
               if(this.formData){
                    let dataId = this.formData.dataId;
                    this.$http.get(this.url.queryById,{params:{id:dataId}}).then((res)=>{
                        if(res.data.success){
                            console.log("表单数据",res);
                            this.model = res.data.result;
                        }
                    })
                }
            },
            onSubmit() {
                let myForm = {...this.model};
                this.loading = true;
                let url = myForm.id?this.url.edit:this.url.add;
				this.$http.post(url,myForm).then(res=>{
				   console.log("res",res)
				   this.loading = false
				   this.$Router.push({name:this.backRouteName})
				}).catch(()=>{
					this.loading = false
				});
            }
        }
    }
</script>
